package a.acceltest;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.Toast;

public class Home extends Activity implements OnTouchListener {
	screen HOME;
	float nxs = 0, nxe = 0, nys = 0, nye = 0;
	float exs = 0, exe = 0, eys = 0, eye = 0;
	Bitmap bk, logo, nw, nwc, ext, extc, albm, albmc;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		HOME = new screen(this);
		HOME.setOnTouchListener(this);
		setContentView(HOME);
	}

	public boolean onTouch(View v, MotionEvent event) {
		float x = event.getX();
		float y = event.getY();
		if(x>=nxs && x<=nxe && y>=nys && y<=nye){
			Intent I = new Intent("android.intent.action.OPTION");
			startActivity(I);
		}
		if(x>=exs && x<=exe && y>=eys && y<=eye){
			this.finish();
		}
		return false;
	}

	public class screen extends View{

		public screen(Context context) {
			super(context);
			logo = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
			nw = BitmapFactory.decodeResource(getResources(), R.drawable.new1);
			albm = BitmapFactory.decodeResource(getResources(), R.drawable.album);
			ext = BitmapFactory.decodeResource(getResources(), R.drawable.exit1);
			bk = BitmapFactory.decodeResource(getResources(), R.drawable.bkgrnd);
		}

		public void onDraw(Canvas canvas){
			canvas.drawColor(Color.BLACK);
			canvas.drawBitmap(bk, ((canvas.getWidth()/2)-(bk.getWidth()/2)), 0, null);
			canvas.drawBitmap(logo, ((canvas.getWidth()/2)-(logo.getWidth()/2)), canvas.getHeight()/20, null);
			canvas.drawBitmap(nw, ((canvas.getWidth()/2)-(nw.getWidth()/2)), canvas.getHeight()/4, null);
			canvas.drawBitmap(albm, ((canvas.getWidth()/2)-(albm.getWidth()/2)), 2*canvas.getHeight()/4, null);
			canvas.drawBitmap(ext, ((canvas.getWidth()/2)-(ext.getWidth()/2)), 3*canvas.getHeight()/4, null);
			nxs = (canvas.getWidth()/2)-(nw.getWidth()/2);
			nxe = nxs+nw.getWidth();
			nys = canvas.getHeight()/4;
			nye = nys+nw.getHeight();	
			exs = (canvas.getWidth()/2)-(ext.getWidth()/2);
			exe = exs+ext.getWidth();
			eys = 3*canvas.getHeight()/4;
			eye = eys+ext.getHeight();	
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater options = getMenuInflater();
		options.inflate(R.menu.activity_home, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId()){
		case R.id.menu_settings:
			Toast.makeText(this, "You pressed the icon!", Toast.LENGTH_LONG).show();
			break;
		}
		return false;
	}
}